package tool.encrypt;

import tool.Base64Tool;

public class IdentifyTool {

	public static String enCodeCid(Integer cid){
		return "KH_"+new Integer(cid*2+3).toString();
	}
	
	public static Integer deCode(String idCode,Integer type){
		Integer result=0;	
		switch(type){
		case 1:		// client
			result =   (new Integer(idCode.substring(3))-3)/2;
			break;
		case 2:		// user
			result =   (new Integer(idCode.substring(3))-3)/2;
			break;
		}
		return result;
	}
	
	
	/**
	 * @param type 1:cid 2:udi
	 */
	public static String enCodeByEncrypt(Integer id,Integer type){
		String result="";	
		switch(type){
		case 1:		// client
			result =  Base64Tool.encode("KH_"+new Integer(id*2+3).toString());
			break;
		case 2:		// user
			result =  Base64Tool.encode("YH_"+new Integer(id*2+3).toString());
			break;
		}
		return result;
	}
	
	/**
	 * 
	 * @param idCode
	 * @param type 1:cid  2:uid
	 * @return
	 */
	public static Integer deCodeByEncrypt(String idCode,Integer type){
		Integer result=0;	
		switch(type){
		case 1:		// client
			result =   (new Integer((Base64Tool.decode(idCode)).substring(3))-3)/2;
			break;
		case 2:		// user
			result =   (new Integer((Base64Tool.decode(idCode)).substring(3))-3)/2;
			break;
		}
		return result;
	}
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
